package openbang.account.web.portal.widget;


import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * 显示消息的内容
 * 
 * @author aibo zeng
 *
 */

public class MsgDetailWidget  extends DialogBox{

	private static String title = "消息内容";
	
	private VerticalPanel vPanelMenu = new VerticalPanel();
	private TextArea bodyHtml = new TextArea();
	private Button closeButton = new Button("关闭");
	
	public MsgDetailWidget() {
	    setText(title);
	    setWidget(vPanelMenu);
	    setAnimationEnabled(true);
	    setGlassEnabled(true);
	    vPanelMenu.add(bodyHtml);
	    bodyHtml.setSize("300px","200px");
	    bodyHtml.setReadOnly(true);
	    vPanelMenu.add(closeButton);
	    closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				hide();
			}
		});
	  }
	
	 /**
	  * 显示消息的内容
	  * @param msgReceive
	  */
	 public void viewMsg(String msgBody){		 
		 bodyHtml.setText(msgBody);
	 }

	  @Override
	  protected void onPreviewNativeEvent(NativePreviewEvent preview) {
	    super.onPreviewNativeEvent(preview);

	    NativeEvent evt = preview.getNativeEvent();
	    if (evt.getType().equals("keydown")) {
	      // Use the popup's key preview hooks to close the dialog when either
	      // enter or escape is pressed.
	      switch (evt.getKeyCode()) {
	        case KeyCodes.KEY_ENTER:
	        case KeyCodes.KEY_ESCAPE:
	          hide();
	          break;
	      }
	    }
	  }
}
